package com.cskaoyan.controller;


import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.User;
import com.cskaoyan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@RestController
@RestControllerAdvice
@RequestMapping("user")
public class UserController {
    @Autowired
    UserService service;

      @RequestMapping(value = "login",method = RequestMethod.POST)
    public BaseRespVo login(@RequestBody User user, HttpServletResponse response){
          int id = service.insertUser(user);
          user.setId(id);
          Cookie cookie = new Cookie("user", user.getUsername());
           response.addCookie(cookie);
          return BaseRespVo.ok();
      }
      @RequestMapping("hello")
    public BaseRespVo hello(){
          return BaseRespVo.ok();
      }

}
